<?php
//$brand=R::findOne("shop_brands","lib_lt = ? ",array($currentObject->brandid));
//calcule quantities

$all = R::findAll('emsupply_evolution','productId = ? ',array($currentObject->id));

$total=0;

foreach ($all as $stock)
{
	$operation=R::load("emsupply_operations", $stock->operationId);
	if ($operation->name=="remove")
		$total-=$stock->quantity;
		elseif($operation->name=="add")
	$total+=$stock->quantity;
	
}

$total=$total*$currentObject->paquet_m;
if ($total==0) {$total="Stock Epuisé";}else
		
{
	if (inGroup("Client"))
	{

	
	$category = R::findOne('emsupply_category','lib = ? ',array($currentObject->categoryid));
	$palier= $category->palier;

$total=(floor($total/$palier)*$palier);
if ($total==0) 
	$total="Moins de ".$palier;
	else
$total="Plus de ".$total;

		}


}


echo $total;
?>

